package com.mingyuan.library.domain.lending.patron.event;

import com.mingyuan.library.domain.lending.book.model.valueobject.BookId;
import com.mingyuan.library.domain.lending.book.model.valueobject.BookType;
import com.mingyuan.library.domain.lending.librarybranch.model.valueobject.LibraryBranchId;
import com.mingyuan.library.domain.lending.patron.model.valueobject.HoldDuration;
import com.mingyuan.library.domain.lending.patron.model.valueobject.PatronId;
import lombok.NonNull;
import lombok.Value;

import java.time.Instant;
import java.util.UUID;

/**
 * 预定中的图书信息
 *
 * @author yangzk
 * @date 2023/12/28 19:33
 **/
@Value
public class BookPlacedOnHold implements PatronEvent {
    /**
     * 事件ID
     */
    @NonNull
    UUID eventId = UUID.randomUUID();
    /**
     * 预定时间
     */
    @NonNull
    Instant when;
    /**
     * 读者ID
     */
    @NonNull
    UUID patronId;
    /**
     * 图书ID
     */
    @NonNull
    UUID bookId;
    /**
     * 图书类型
     */
    @NonNull
    BookType bookType;
    /**
     * 图书馆分馆ID
     */
    @NonNull
    UUID libraryBranchId;
    /**
     * 预定开始时间
     */
    @NonNull
    Instant holdFrom;
    /**
     * 预定截止时间
     */
    Instant holdTill;

    public static BookPlacedOnHold bookPlacedOnHoldNow(BookId bookId, BookType bookType, LibraryBranchId libraryBranchId, PatronId patronId, HoldDuration holdDuration) {
        return new BookPlacedOnHold(
                Instant.now(),
                patronId.getPatronId(),
                bookId.getBookId(),
                bookType,
                libraryBranchId.getLibraryBranchId(),
                holdDuration.getFrom(),
                holdDuration.getTo().getOrNull());
    }
}